#include "nntp.h"
#include <sstream>
#ifdef DEBUG
#include <iostream>
#define trace if(false) cout
#endif

unsigned int NNTP::string_to_int(string& input)
{
	unsigned char c1 = input[0];
	unsigned char c2 = input[1];
	unsigned char c3 = input[2];
	unsigned char c4 = input[3];

	unsigned int i = (c1 << 24) | (c2 << 16) | (c3 << 8) | c4;
	trace << i << endl;
	return i;
}	

string  NNTP::int_to_string(unsigned int& d)
{
	string answer(4, 0);
	answer[0] = (d >> 24) & 0xFF;
	answer[1] = (d >> 16) & 0xFF;
	answer[2] = (d >> 8) & 0xFF;
	answer[3] = d & 0xFF;
	return answer;
}

void NNTP::add_par_string(string& dest, unsigned int& N, string& param)
{
	string tmp;
	dest += Protocol::PAR_STRING;
	dest += int_to_string(N);
	dest += param;
}	

void NNTP::add_par_num(string& dest, unsigned int N)
{
	string tmp;
	dest += Protocol::PAR_NUM;
	dest += int_to_string(N);
}
